﻿using SunnyPaine.Autofac.Extension.SqlSugar.Entities;
using SunnyPaine.Autofac.Extension.SqlSugar.Service;
using SunnyPaine.Autofac.Extension.SqlSugar.Test.Model;
using SunnyPaine.Autofac.Extension.Stereotype.Attributes;
using System;

namespace SunnyPaine.Autofac.Extension.SqlSugar.Test.Service.Impl
{
    [Service]
    [Transaction]
    public class UserService : ServiceImpl<User>, IUserService
    {
        [Resource]
        private IGoodsService GoodsService { get; set; }

        [TransactionScope]
        public override void Add(User user)
        {
            Goods goods = new Goods()
            {
                Id = "g" + DateTime.Now.ToString("yyyyMMddHHmmssfff"),
                Name = $"goods of {user.Name}",
                Price = new decimal(98.99D)
            };

            base.Add(user);
            this.GoodsService.Add(goods);
        }
    }
}
